﻿<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Advertising.ascx.cs" Inherits="controls_admin_Advertising" %>
<!-- table -->
<script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
<script src="../Scripts/jquery.tablednd_0_5.js" type="text/javascript"></script>
<script type="text/javascript">
    var variable = "0";
    var mid = <%=mid%>;
    var j = jQuery.noConflict();
    j(document).ready(function () {    
        j("#btnAdd").click(function () {
            window.location.replace(window.location.pathname + "?module=advertisingadd" );            
        });                
        j('#table-3').tableDnD({
            onDrop: function (table, row) {
                variable = j.tableDnD.serialize();
            }
        });                
        j("#<%=btnDel.ClientID%>").click(function () {
            var index = "";
            j("table input[type=checkbox].item").each(function () {
                var checked = j(this).attr("checked");
                if (checked) {
                    index = index + j(this).attr("value") + ";";
                }
            });
            j("#<%=hdfCheck.ClientID%>").val(index);
            if(index == "") return false;
            else return confirm("Xác nhận xóa !");            
        });
        j("#<%=update.ClientID%>").click(function () {
            if (variable == "0")
                return false;
            j.ajax({
                type: "POST",
                url: "../services/WebService.asmx/adsorder",
                data: "{'id':'&" + variable + "','mid':'" + mid + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                beforeSend: function () {
                    j("#<%=divMessage.ClientID %>").html("");
                },
                success: function (message) {
                    if (message.d == false) {
                        j("#<%=divMessage.ClientID %>").html("<div id='message-error' class='message message-error'><div class='image'><img src='../resources/images/icons/error.png' alt='Error' height='32' /></div><div class='text'><h6>Lỗi</h6><span>Chưa thực hiện được!</span></div><div class='dismiss'><a href='#message-error'></a></div></div>");
                    }
                    else {
                        j("#<%=divMessage.ClientID %>").html("<div id='message-success' class='message message-success'><div class='image'><img src='../resources/images/icons/success.png' alt='Success' height='32' /></div><div class='text'><h6>Thông Báo</h6><span>Cập nhật thành công !</span></div><div class='dismiss'><a href='#message-success'></a></div></div>");
                    }
                },
                error: function (errormessage) {
                    j("#<%=divMessage.ClientID %>").html("<div id='message-error' class='message message-error'><div class='image'><img src='../resources/images/icons/error.png' alt='Error' height='32' /></div><div class='text'><h6>Lỗi</h6><span>Chưa thực hiện được!</span></div><div class='dismiss'><a href='#message-error'></a></div></div>");
                }
            });
        });
    });
</script>
<asp:HiddenField ID="hdfCheck" runat="server" />
<div class="box">
    <!-- box / title -->
    <div class="title">
        <h5 runat="server" id="title">
            Danh sách quảng cáo
        </h5>
    </div>
    <div id="divMessage" runat="server">
    </div>
    <div id="divResult" class="result" runat="server">
    </div>
    <div class="first-action">
        <asp:DropDownList ID="ddlModule" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlModule_SelectedIndexChanged"
            CssClass="select">
        </asp:DropDownList>
    </div>
    <!-- end box / title -->
    <div class="table">
        <table id="table-3">
            <asp:Repeater ID="rptAds" runat="server">
                <HeaderTemplate>
                    <thead>
                        <tr>
                            <th>
                                STT
                            </th>
                            <th>
                                Ảnh - Flash
                            </th>
                            <th>
                                Tên quảng cáo
                            </th>
                            <th>
                                Link tới
                            </th>
                            <th>
                                Sửa
                            </th>
                            <th class="selected last">
                                <input type="checkbox" class="checkall" />
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr id='<%#Eval("PICTURE_ID")%>' style="cursor: move">
                        <td align="center">
                            <%#(Container.ItemIndex+1)+(base.Cur_page-1)*base.Page_size %>
                        </td>
                        <td align="center">
                            <%#GetAds(Eval("URL").ToString(),Eval("PICTURE_NAME_VN").ToString())%>
                        </td>
                        <td align="center">
                            <%#Eval("PICTURE_NAME_VN")%>
                        </td>
                        <td align="center">
                            <%#Eval("TARGET_LINK")%>
                        </td>
                        <td align="center">
                            <a href='default.aspx?module=advertisingedit&aid=<%#Eval("PICTURE_ID")%>'>
                                <img src="../Resources/icons/16x16/edit.png" alt='<%#Eval("PICTURE_NAME_VN")%>' />
                            </a>
                        </td>
                        <td align="center" class="last">
                            <input type="checkbox" value="<%#Container.ItemIndex%>" class="item" />
                        </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </tbody>
                </FooterTemplate>
            </asp:Repeater>
        </table>
        <div class="action">
            <div class="button">
                <input id="btnAdd" value="Thêm Mới" type="button" />
                <asp:Button ID="btnDel" runat="server" Text="Xóa" OnClick="btnDel_Click" />
                <input type="button" value="Cập nhật thứ tự" id="update" runat="server" />
            </div>
        </div>
        <div class="pagination pagination-left last">
            <div class="pagerContainer" id="pagerContainer" runat="server" />
        </div>
    </div>
</div>
